<?php
/**
 * Created by PhpStorm.
 * User: shaowei
 * Date: 2019/2/15
 * Time: 下午2:43
 */

namespace App\Http\Services;


use App\Http\Model\Ad;
use App\Http\Model\FinanceRechargeOrder;
use App\Http\Model\FinanceUserWallet;
use App\Http\Model\Friends;
use App\Http\Model\Gift;
use App\Http\Model\Mall;
use App\Http\Model\NoviceChatLog;
use App\Http\Model\Room;
use App\Http\Model\RoomUser;
use App\Http\Model\System;
use App\Http\Model\SystemConfig;
use App\Http\Model\Trends;
use App\Http\Model\Union;
use App\Http\Model\User;
use App\Http\Model\UserLoginLog;
use App\Lib\rc;
use App\Modules\Relationship\Models\QueueExecModel;
use Illuminate\Support\Facades\Log;
use App\Http\Services\MaximumGoldRoomServices;
use App\Lib\SendSms;

class MsgServices extends CommonServices
{
    public $model_room;
    private $lib_rong;
    private $chat_room_id;
    private $defender_room_id = 106;
    private $chat_room_name;
    private $modelSystem;
    protected $modelWallet;
    protected $modelSystemConfig;
    protected $noviceChatLog;
    public function __construct()
    {
        parent::__construct();

        $this->lib_rong = new rc();
        $this->chat_room_id = config('rong_cloud.chat_room_id');
        $this->chat_room_name = config('rong_cloud.chat_room_name');
        $this->modelSystem = new System();
        $this->modelWallet = new FinanceUserWallet();
        $this->modelSystemConfig = new SystemConfig();
        $this->noviceChatLog = new NoviceChatLog();
        $this->model_room = new Room();
    }


    /**
     * 开播消息
     * @param $room_id
     */
    public function room_opened($room_id, $user_id)
    {
        $room = $this->model_room->get_room($room_id);
        //小屋开播提醒10分钟内发一下
        if($room['business_type'] == 0){
            if($this->model_room->getBroadcastMsg($room_id)){
                return;
            }else{
                $this->model_room->setBroadcastMsg($room_id);
            }
        }
        $users = $this->model_room->get_collect_users($room_id);
        $micro_user = $this->user->get_user($user_id);
        $uids = [];
        foreach ($users as $user) {
            if ($user_id == $user['user_id']) {
                continue;
            }
            $uids[] = $user['user_id'];
        }
        if (empty($uids)) {
            return;
        }
        $data = [
            'k' => 40001,
            'rid' => $room_id,
            "rn" => $room['name'],
            "uid" => $micro_user['user_id'],
            "nn" => $micro_user['nickname'],
        ];
        $this->lib_rong->send_system_msg(11, $uids, 'kk:room_start', $data, $micro_user['nickname'] . '开播了～赶快进来', 'yyaudio://room/info?id='.$room_id);
    }


    /**
     * 充值消息
     * @param $order_id
     */
    public function recharge($order_sn)
    {
        $model_order = new FinanceRechargeOrder();
        $order = $model_order->getOrderBySn($order_sn);
        $data = [
            "k" => 40002,
            "price" => $order['price'],
        ];

        // TODO 判断充值类型使用参数
        switch ($order['recharge_type'] ?? 0) {
            case 0:// 钻石
                $data['amount'] = $order['diamond_amount'] ?? 0;
                break;
            case 1:// 珍珠

            default:
                break;
        }

        $this->lib_rong->send_system_msg(11, $order['user_id'], 'kk:recharge', $data);

        # 发送支付消息
        $dataPush = [];
        $dataPush['taskname'] = 'recharge';
        $dataPush['time'] = time();
        $dataPush['order_id'] = $order['order_id'] ?? 0;
        $dataPush['order_sn'] = $order['order_sn'] ?? '';
        $dataPush['user_id'] = $order['user_id'] ?? 0;
        $dataPush['price'] = $order['price'] ?? 0;
        $dataPush['pay_type'] = $order['pay_type'] ?? 0;
        $dataPush['recharge_type'] = $order['recharge_type'] ?? 0;

        // 写入日志
        (new QueueExecModel())->insertRecord($dataPush);
    }


    /**
     * 财富升级消息
     */
    public function rank_update($user_id, $rank_name, $rank_image = "", $wealth_balance = 0)
    {
        $userRoomId = intval((new RoomUser())->get_user_cur_room($user_id));//用户所在当前房间
        $userInfo = (new User())->get_user($user_id);
        $data = [
            "k" => 40003,
            "rn" => $rank_name,
            "image" => $rank_image,
            "user_id" => $user_id,
            "user_nickname" => $userInfo['nickname'],
            "user_image" => $userInfo['images'][0],
            "room_id" => $userRoomId,
            "show_to_all" => intval((new FinanceWalletServices())->checkUserWealthBalanceGreaterThanNumber($user_id, (new SystemConfig())->getLevelUpMsgShowToAllMinWealthBalance())),
        ];

        $this->lib_rong->send_system_msg(11, $user_id, 'kk:rank_update', $data);

        //财富值小于10万不发消息
        if($wealth_balance < 10000){
            return;
        }

//        $data['k'] = 30139;
//        (new RoomMsgServices())->send_room_msg($userRoomId, $data);//发房间消息
    }

    /**
     * 魅力升级消息
     */
    public function charm_rank_update($user_id, $rank_name, $rank_image,$charm_balance)
    {
        $userRoomId = intval((new RoomUser())->get_user_cur_room($user_id));//用户所在当前房间
        $userInfo = (new User())->get_user($user_id);
        $data = [
            "k" => 40006,
            "rn" => $rank_name,
            "image" => $rank_image,
            "user_id" => $user_id,
            "user_nickname" => $userInfo['nickname'],
            "user_image" => $userInfo['images'][0],
            "room_id" => $userRoomId,
            "show_to_all" => intval((new FinanceWalletServices())->checkUserCharmBalanceGreaterThanNumber($user_id, (new SystemConfig())->getLevelUpMsgShowToAllMinCharm())),
        ];
        $this->lib_rong->send_system_msg(11, $user_id, 'kk:charm_rank_update', $data);

        //魅力值小于10万不发消息
        if($charm_balance < 10000){
            return;
        }
//        $data['k'] = 30140;
//        (new RoomMsgServices())->send_room_msg($userRoomId, $data);//发房间消息
    }

    /**
     * 添加管理员消息
     */
    public function role_add($user_id, $room_id)
    {
        $room = $this->model_room->get_room($room_id);
        $data = [
            "k" => 40004,
            'rid' => $room_id,
            "rn" => $room['name']
        ];
        $this->lib_rong->send_system_msg(11, $user_id, 'kk:role_add', $data);
    }

    /**
     * 动态关注人消息
     * @param $content_id
     */
    public function trends_fans($content_id)
    {
        $model_trends = new Trends();
        $model_friends = new Friends();
        $content = $model_trends->trend($content_id);
        $fans_uids = [];
        $fans = $model_friends->get_fans($content['user_id']);
        foreach ($fans as $item) {
            $fans_uids[] = $item['user_id'];
        }
        if (empty($content) || empty($fans_uids)) {
            return;
        }
        $user = $this->user->get_user($content['user_id']);
        $user_image = '';
        if (!empty($user['images'])) {
            $user_image = $user['images'][0];
        }
        $cv = $content['c_cover'];
        if ($content['c_type'] == 2 && !empty($content['c_imgs'])) {
            $tmp_arr = explode(', ', $content['c_imgs']);
            $cv = $tmp_arr[0];
        }

        $cTypeDesc = $model_trends -> getCtypeMap($content['c_type']);

        $data = [
            "k" => 50001,
            "cid" => $content['content_id'],
            "cont" => $content['c_content'],
            "cv" => $cv,
            "ct" => $content['c_type'],
            "ctd" => (string)$cTypeDesc,
            "uid" => $content['user_id'],
            "nn" => $user['nickname'],
            "img" => $user_image ,
            "sex" => $user['gender'],
            "bron" => $user['birthday']
        ];
        $this->lib_rong->send_system_msg(13, $fans_uids, 'kk:dynamic', $data);
    }


    /**
     * 动态互动通知
     * @param $content_id
     */
    public function trends_interaction($content_id)
    {
        $model_trends = new Trends();
        $content = $model_trends->trend($content_id);
        if (empty($content)) {
            return;
        }
        $cont = json_decode($content['c_content'], true);
        $uids = [];
        if (!empty($cont)) {
            foreach ($cont as $item) {
                if (intval($item['type']) == 1) {
                    $uids[] = intval($item['us_id']);
                }
            }
        }
        if (empty($uids)) {
            return;
        }
        $user = $this->user->get_user($content['user_id']);
        $user_image = '';
        if (!empty($user['images'])) {
            $user_image = $user['images'][0];
        }
        $cv = $content['c_cover'];
        if ($content['c_type'] == 2 && !empty($content['c_imgs'])) {
            $tmp_arr = explode(', ', $content['c_imgs']);
            $cv = $tmp_arr[0];
        }

        $cTypeDesc = $model_trends -> getCtypeMap($content['c_type']);

        $data = [
            "k" => 60001,
            "cid" => $content['content_id'],
            "cont" => $content['c_content'],
            "cv" => $cv,
            "ct" => $content['c_type'],
            "ctd" => (string)$cTypeDesc,
            "uid" => $content['user_id'],
            "nn" => $user['nickname'],
            "img" => $user_image,
            "sex" => $user['gender'],
            "bron" => $user['birthday']
        ];
        $this->lib_rong->send_system_msg(13, $uids, 'kk:dynamic', $data);
    }

    /**
     * xx赞了你的动态
     * @param $content_id
     */
    public function trends_won($content_id, $user_id)
    {
        $model_trends = new Trends();
        $content = $model_trends->trend($content_id);
        if (empty($content)) {
            return;
        }
        if ($content['user_id'] == $user_id) {
            return;
        }
        $user = $this->user->get_user($user_id);
        $user_image = '';
        if (!empty($user['images'])) {
            $user_image = $user['images'][0];
        }
        $cv = $content['c_cover'];
        if ($content['c_type'] == 2 && !empty($content['c_imgs'])) {
            $tmp_arr = explode(', ', $content['c_imgs']);
            $cv = $tmp_arr[0];
        }
        $cTypeDesc = $model_trends -> getCtypeMap($content['c_type']);

        $data = [
            "k" => 60002,
            "cid" => $content['content_id'],
            "cont" => $content['c_content'],
            "cv" => $cv,
            "ct" => $content['c_type'],
            "ctd" => (string)$cTypeDesc,
            "uid" => $user['user_id'],
            "nn" => $user['nickname'],
            "img" => $user_image,
            "sex" => $user['gender'],
            "bron" => $user['birthday']
        ];
        $this->lib_rong->send_system_msg(13, $content['user_id'], 'kk:dynamic', $data);
    }


    /**
     * xx查看了你的动态
     * @param $content_id
     * @param $user_id
     */
    public function trends_read($content_id, $user_id)
    {
        $model_trends = new Trends();
        $content = $model_trends->trend($content_id);
        if (empty($content)) {
            return;
        }
        if ($content['user_id'] == $user_id) {
            return;
        }
        $user = $this->user->get_user($user_id);
        $user_image = '';
        if (!empty($user['images'])) {
            $user_image = $user['images'][0];
        }
        $cv = $content['c_cover'];
        if ($content['c_type'] == 2 && !empty($content['c_imgs'])) {
            $tmp_arr = explode(', ', $content['c_imgs']);
            $cv = $tmp_arr[0];
        }

        //查看动态业务 (同⼀一⽤用户在1⼩小时内多次查看同⼀一动态只推送1次)
        if ($model_trends->getTrendReadPushCache($content_id, $user_id)) {
            return false;
        } else {
            $model_trends->setTrendReadPushCache($content_id, $user_id);
        }
        $cTypeDesc = $model_trends -> getCtypeMap($content['c_type']);

        $data = [
            "k" => 60003,
            "cid" => $content['content_id'],
            "cont" => $content['c_content'],
            "cv" => $cv,
            "ct" => $content['c_type'],
            "ctd" => (string)$cTypeDesc,
            "uid" => $user['user_id'],
            "nn" => $user['nickname'],
            "img" => $user_image,
            "sex" => $user['gender'],
            "bron" => $user['birthday']
        ];
        $this->lib_rong->send_system_msg(13, $content['user_id'], 'kk:dynamic', $data);
    }


    /**
     * xx 评论了你的动态
     * @param $content_id
     * @param $user_id
     */
    public function trends_comments($content_id, $user_id, $comment_text, $voice_resource)
    {
        $model_trends = new Trends();
        $content = $model_trends->trend($content_id);
        if (empty($content)) {
            return;
        }
        $user = $this->user->get_user($user_id);

        if ($content['user_id'] == $user_id) {
            return;
        }

        $user_image = '';
        if (!empty($user['images'])) {
            $user_image = $user['images'][0];
        }
        $cv = $content['c_cover'];
        if ($content['c_type'] == 2 && !empty($content['c_imgs'])) {
            $tmp_arr = explode(', ', $content['c_imgs']);
            $cv = $tmp_arr[0];
        }
        $cTypeDesc = $model_trends -> getCtypeMap($content['c_type']);

        $data = [
            "k" => 60005,
            "cid" => $content['content_id'],
            "cont" => $content['c_content'],
            "text" => $comment_text,
            "voice" => $voice_resource,
            "cv" => $cv,
            "ct" => $content['c_type'],
            "ctd" => (string)$cTypeDesc,
            "uid" => $user['user_id'],
            "nn" => $user['nickname'],
            "img" => $user_image,
            "sex" => $user['gender'],
            "bron" => $user['birthday']
        ];
        $this->lib_rong->send_system_msg(13, $content['user_id'], 'kk:dynamic', $data);
    }


    /**
     * xx查看了你的个人资料
     * @param $self_user_id
     * @param $user_id
     */
    public function personal_read($self_user_id, $user_id)
    {
        if ($self_user_id == $user_id) {
            return;
        }
        $user = $this->user->get_user($user_id);
        $user_image = '';
        if (!empty($user['images'])) {
            $user_image = $user['images'][0];
        }
        $data = [
            "k" => 60004,
            "uid" => $user['user_id'],
            "nn" => $user['nickname'],
            "img" => $user_image,
            "sex" => $user['gender'],
            "bron" => $user['birthday']
        ];
        $this->lib_rong->send_system_msg(13, $self_user_id, 'kk:look_user', $data);
    }

    /**
     * 赠送礼物
     * @param $send_user_id
     * @param $recv_user_id
     * @param $gift_id
     * @param $gift_count
     */
    public function give_gift($send_user_id, $recv_user_id, $gift_id, $gift_count)
    {
        $model_gift = new Gift();
        $send_user = $this->user->get_user($send_user_id);
        $recv_user = $this->user->get_user($recv_user_id);
        $gift = $model_gift->get_gift($gift_id);
        if (empty($send_user) || empty($recv_user) || empty($gift)) {
            return;
        }
        $suser_image = '';
        if (!empty($send_user['images'])) {
            $suser_image = $send_user['images'][0];
        }
        $ruser_image = '';
        if (!empty($recv_user['images'])) {
            $ruser_image = $recv_user['images'][0];
        }
        $data = [
            "k" => 70001,
            "gid" => $gift['gift_id'],
            "gc" => $gift_count,
            "gn" => $gift['name'],
            "img" => $gift['image'],
            "res" => $gift['animate_resource'],  // 礼物资源
            "suid" => $send_user['user_id'],        // 发送人用户ID
            "snn" => $send_user['nickname'],      // 发送人用户昵称
            "simg" => $suser_image,
            "ruid" => $recv_user['user_id'],       // 接受人用户ID
            "rnn" => $recv_user['nickname'],     // 接受人用户昵称
            "rimg" => $ruser_image,
            'gift_name' => $gift['name'] ?? '',
            'gift_image' => $gift['image'] ?? '',
            'gift_resource' => $gift['animate_resource'] ?? '',
            'gift_resource_md5' => $gift['animate_resource_md5'] ?? '',
        ];
        //$this->lib_rong->send_private_msg($send_user_id, $recv_user_id, 'kk:send', $data);
    }


    /**
     * 赠送商品
     * @param $send_user_id
     * @param $recv_user_id
     * @param $goods_id
     */
    public function give_mall($send_user_id, $recv_user_id, $goods_id)
    {
        $model_mall = new Mall();
        $goods = $model_mall->get_goods($goods_id);
        $send_user = $this->user->get_user($send_user_id);
        $recv_user = $this->user->get_user($recv_user_id);
        $suser_image = '';
        if (!empty($send_user['images'])) {
            $suser_image = $send_user['images'][0];
        }
        $ruser_image = '';
        if (!empty($recv_user['images'])) {
            $ruser_image = $recv_user['images'][0];
        }
        //商品类型 0=其它 1=尊贵头像框 2=进场特效 3=气泡 4=名片 5=主页飘 6=尾灯 7=座驾 8=娱乐头像框 9=游戏皮肤
        $k = 70002;
        if ($goods['goods_type'] == 1) {
            $k = 70003;
        }
        if ($goods['goods_type'] == 2) {
            $k = 70002;
        }
        if ($goods['goods_type'] == 3) {
            $k = 70004;
        }
        $data = [
            "k" => $k,       // 信令Code
            "gid" => $goods['goods_id'],
            "gn" => $goods['goods_name'],
            "gsimg" => $goods['small_img'],
            "gbimg" => $goods['big_img'],
            "gres" => $goods['animate_resource'],
            "suid" => $send_user['user_id'],        // 发送人用户ID
            "snn" => $send_user['nickname'],      // 发送人用户昵称
            "simg" => $suser_image,
            "ruid" => $recv_user['user_id'],       // 接受人用户ID
            "rnn" => $recv_user['nickname'],     // 接受人用户昵称
            "rimg" => $ruser_image,
        ];
        $this->lib_rong->send_private_msg($send_user_id, $recv_user_id, 'kk:send', $data);
    }


    /**
     * 版本升级
     * @param $id
     */
    public function release_version($id)
    {
        $model_system = new System();
        $version = $model_system->get_version($id);
        $data = [
            "k" => 80001,                       // 信令Code
            "vid" => $version['version_id'],    // 软件版本号
            "url" => $version['download_url'],  // 软件包地址
            "pid" => $version['platform_id'],   // 平台ID 2、Android 1、IOS
            "type" => $version['upgrade_type'], // 升级类型 0.不升级 1. 强制升级 2.普通升级
            "desc" => $version['describe'],     // 升级说明
            "cid" => $version['channel_id']     // 渠道ID
        ];
        $this->lib_rong->broadcast(14, 'kk:update', $data, 0);
    }

    /**
     * 红包雨即将开始全员通知
     */
    public function redPacketRainMsg($redPacketRain)
    {
        $data = [
            "k" => 80015,
            "redPacketRain" => $redPacketRain,
        ];
        $res = $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:red_packet_rain_msg', $data);
    }

    /**
     * 新版本全员推送服务
     *
     * @param [type] $is_all [1=>全员0=>非全员]
     * @param [type] $userids [用户id数组]
     * @param [type] $send_content [发送文案]
     * @param [type] $send_type [1=>图文0=>文案]
     * @param [type] $title [图文标题]
     * @param [type] $img_url [图片地址]
     * @param [type] $action_url [跳转URL]
     * @return void
     */
    public function newSendNotify($is_all,$userids,$send_content,$send_type,$title,$img_url,$action_url,$notify_type)
    {   
        if($notify_type == 1){
            $this->officeNotify($is_all,$userids,$send_content,$send_type,$title,$img_url,$action_url, 80002, $notify_type,'kk:activity');
        }else{
            $this->officeNotify($is_all,$userids,$send_content,$send_type,$title,$img_url,$action_url, 80007, $notify_type,'kk:activity');
        }
        return true;
    }

    //处理不同请求下的官方请求消息
    public function officeNotify($is_all, $userids, $send_content, $send_type, $title, $img_url, $action_url, $kcode, $notify_type, $objectName){
        //图文
        if($send_type == 1)
        {
            $data = [
                "k" => $kcode,                           // 信令Code
                "n" => $title.PHP_EOL.$send_content,                     // 活动推广文字
                "img" => build_image($img_url),                    // 活动图片
                "url" => $action_url,                    // 打开地址
                "action" => $action_url,
                "outside" => 0,    // 打开方式 0.软件内webview 、1.系统浏览器
            ];
        }else{
            $data = [
                "k" => $kcode,                           // 信令Code
                "n" => $send_content,                     // 活动推广文字
                "url" => $action_url,                    // 打开地址
                "action" => $action_url,
                "outside" => 0,    // 打开方式 0.软件内webview 、1.系统浏览器
            ];
        }
        $adminUserId = 14;//默认官方通知用户
        $pushContent = '官方推送';
        if($notify_type == 2){
            $adminUserId = 17;//游戏消息通知用户
            $pushContent = '官方游戏推送';
        }
         //非全员推送
         if($is_all == 0)
         {
             $this->lib_rong->send_system_msg($adminUserId, $userids, $objectName, $data,$pushContent,$pushContent);
         }else{
            $this->lib_rong->broadcast($adminUserId, $objectName, $data, 0);
         }
    }

    /**
     * 发送全服消息
     * @param $gift_name
     * @param $gift_num
     * @param $user_id
     * @param $room_id
     */
    public function all_gift($gift_name, $gift_num, $user_id, $room_id, $gift_total=0)
    {
        $user = $this->user->get_user($user_id);
        if (empty($user)) return;

        $room = $this->model_room->get_room($room_id);
        if (empty($room)) return;

        //获取用户设置
        $userModel = new User();
        $userSet = $userModel->getUserSet($user_id);
        if ($userSet['gift_notice'] != 1) {
            return;
        }

        //查询指定特殊飘屏配置
        $specialFullScreenInfo = $this->modelSystem->getFullScreen(66);
        $roomIds = [];
        $id = 25;
        if(!empty($specialFullScreenInfo)){
            $roomIds = explode(',', $specialFullScreenInfo['room_ids']);
        } 
        if(!in_array($room_id, $roomIds)){
            //$id = $specialFullScreenInfo['id'];
            $iconUrl = '';
            $textParam = ['name'=>$user['nickname'], 'roomName'=>$room['name'], 'giftName'=>$gift_name,'giftNum'=>$gift_num];
            $actionParam = ['roomId'=>$room_id];
            $extendParam = ['roomId'=>$room_id, 'giftPrice'=>$gift_total];
            $this->sendFullScreen($id, $iconUrl, $textParam, $actionParam, $extendParam);
        } 
    }

    /**
     * 创建聊天室
     * @return bool
     */
    public function create_chat_room()
    {
        $ret = $this->lib_rong->create_chat_room($this->chat_room_id, $this->chat_room_name);
        return $ret;
    }

    /**
     * 查询聊天室信息方法
     * @return bool
     */
    public function query_chat_room()
    {
        $res = $this->lib_rong->query_chat_room($this->chat_room_id);
        return $res;
    }

    /**
     * 加入聊天室
     * @return bool
     */
    public function join_chat_room()
    {
        $res = $this->lib_rong->join_chat_room(11, $this->chat_room_id);
        return $res;
    }

    /**
     * 发送消息 - 礼物飘萍 -废弃 代替通用飘萍sendFullScreen
     * @param string $content
     * @return bool
     */
    public function publish_chat_room($content)
    {
        // write_log(
        //     'CommonFullScreenMsgServices'.(isCli()?'-cli':''),
        //     '[INFO] 发送飘屏消息-已废弃方法-publish_chat_room',
        //     func_get_args()
        // );

        $res = $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:all_gift', $content);
        return $res;
    }

    /**
     * 聊天室保活
     * @return bool
     */
    public function keep_alive_chat_room()
    {
        $content = json_encode(['k' => 80004]);
        $res = $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:keep_alive_chat', $content);
        return $res;
    }

    /**
     * 系统文本消息
     * @param $to_user_id
     * @param $msg
     */
    public function send_sys_text_msg($to_user_id, $msg, $link='', $link_tip='')
    {
        $content = [
            'k' => "80005",
            'n' => $msg,
            'link' => $link,
            'link_tip' => $link_tip,
        ];
        $res = $this->lib_rong->send_system_msg(11, $to_user_id, "kk:sys_text_msg", $content);
        return $res;
    }
    public function send_sys_text_msg_kk($to_user_id, $msg, $link='', $link_tip='')
    {
        $content = [
            'k' => "80012",
            'n' => $msg,
            'link' => $link,
            'link_tip' => $link_tip,
        ];
        $res = $this->lib_rong->send_system_msg(11, $to_user_id, "kk:sys_text_msg", $content);
        return $res;
    }
    /**系统文本消息-可配置参数
     * @param $to_user_id
     * @param $msg
     * @param array $params
     * @return bool
     */
    public function send_sys_customer_msg($to_user_id, $msg ,$params = [])
    {
        $content = [
            'k' => "80025",
            'n' => $msg
        ];
        if(!empty($params)){
            foreach ($params as $k=>$v){
                $content[$k] = $v;
            }
        }
        return $this->lib_rong->send_system_msg(11, $to_user_id, "kk:sys_text_msg", $content);
    }

    /**
     * 私聊文本消息
     * @param $to_user_id
     * @param $msg
     */
    public function send_text_msg($from_user_id, $to_user_id, $msg, $sender = 1)
    {
        $content = [
            'k' => "80005",
            'n' => $msg
        ];
        $res = $this->lib_rong->send_private_msg($from_user_id, $to_user_id, "kk:sys_text_msg", $content, $sender);
        return $res;
    }


    /**
     * 全员警告消息
     * @param $title
     * @param $content
     * @return bool
     */
    public function allWarningMsg($title, $content)
    {
        $data = [
            'k' => 80006,
            't' => $title,
            'n' => $content
        ];
        $data = json_encode($data);
        $res = $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:warning', $data);
        return $res;
    }


    /**
     * 用户警告消息
     * @param $title
     * @param $content
     */
    public function warningMsg($userId, $title, $content, $link='', $link_tip='')
    {
        $data = [
            'k' => 80006,
            't' => $title,
            'link' => $link,
            'link_tip' => $link_tip,
            'n' => $content
        ];
        $res = $this->lib_rong->send_system_msg(11, $userId, "kk:warning", $data);
        return $res;
    }

    /**
     * 简单的全服消息通知
     *
     * @param int $userId 用户ID
     * @param string $nickname 用户昵称
     * @param string $text 附加文本内容
     *
     * @return bool
     */
    public function simpleFullServiceMsgNotify($userId, $text = '')
    {
        $userInfo = $this->user->get_user($userId);

        $data = [
            'k' => 80011,
            'user_id' => $userId,
            'nickname' => $userInfo['nickname'],
            'text' => $text,
        ];

        $data = json_encode($data, JSON_UNESCAPED_UNICODE);
        $res = $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:full_service_msg_notify', $data);
        return $res;
    }

    /*
     * 申请公会消息
     * @param $union_id 公会id
     * @param $to_user_id 推送用户id
     * @param $user_id 处理用户id
     * @param $status 0申请 1同意 2拒绝
     * @param $audit_name 审批人
     */
    public function applyJoinUnionMsg($union_id, $to_user_id, $user_id, $status, $audit_name = '')
    {
        return true;
        $model_union = new Union();
        $union = $model_union->getUnionInfo($union_id);
        $assign_user_info = $this->user->get_user($user_id);
        $data = [
            'k' => 100001,
            'unid' => $union_id,
            "uname" => $union['name'],
            "aname" => $assign_user_info['nickname'],//用户名
            "auuid" => $assign_user_info['user_uid'],//用户uid
            "auid" => $user_id,//用户id
            "status" => $status,//0申请 1同意 2拒绝
            "auditname" => $audit_name,//审批人
            'timestemp' => time(),
        ];
        $this->lib_rong->send_system_msg(10, $to_user_id, 'kk:apply_join_union_msg', $data);
    }

    /*
     * 退出公会消息
     * @param $union_id 公会id
     * @param $to_user_id 推送用户id
     * @param $user_id 处理用户id
     */
    public function quitUnionMsg($union_id, $to_user_id, $user_id)
    {
        $model_union = new Union();
        $union = $model_union->getUnionInfo($union_id);
        $assign_user_info = $this->user->get_user($user_id);
        $data = [
            'k' => 100003,
            'unid' => $union_id,
            "uname" => $union['name'],//公会名
            "aname" => $assign_user_info['nickname'],//用户名
            "auuid" => $assign_user_info['user_uid'],//用户uid
            "auid" => $user_id,//用户id
            'timestemp' => time(),
        ];
        $this->lib_rong->send_system_msg(10, $to_user_id, 'kk:quit_union_msg', $data);
    }

    /*
      * 移除公会消息
      * @param $union_id 公会id
      * @param $to_user_id 推送用户id
      * @param $user_id 处理用户id
      * @param $type 1移出公会  2移出管理层
      * @param $role_name 角色名称
      * @param $audit_name 审批人
      */
    public function removeUnionMsg($union_id, $to_user_id, $user_id, $audit_name, $type = 1, $role_name = '')
    {
        $model_union = new Union();
        $union = $model_union->getUnionInfo($union_id);
        $assign_user_info = $this->user->get_user($user_id);
        $data = [
            'k' => 100004,
            'unid' => $union_id,
            "uname" => $union['name'],//公会名
            "aname" => $assign_user_info['nickname'],//用户名
            "auuid" => $assign_user_info['user_uid'],//用户uid
            "auid" => $user_id,//用户id
            "type" => $type,
            "auditname" => $audit_name,//审批人
            "rolename" => $role_name,//角色名称
            'timestemp' => time(),
        ];
        $this->lib_rong->send_system_msg(10, $to_user_id, 'kk:remove_union_msg', $data);
    }

    ###################################################################################################

    /**
     * 通用飘萍
     * 统一飘萍
     *
     * @param $id 飘萍id
     * @param $iconUrl
     * @param $textParam
     * @param $actionParam
     * @param $extendParam 业务扩展参数  [giftPrice:礼物总金额, roomId:房间ID]
     * @return boolean
     */
    public function sendFullScreen($id, $iconUrl, $textParam, $actionParam, $extendParam = [])
    {
        //审核开关开启时不显示活动飘屏
        if($id == 9 || $id == 6 || $id == 12){
            $examine_switch = $this->modelSystem->getExamineSwitch('switch');
            if($examine_switch == 1){
                return false;
            }
        }
        $fullScreen = $this->modelSystem->getFullScreen($id);
        if (empty($fullScreen)) {
            return false;
        }

        //查看飘屏限制数是否和需要飘屏的价值对比
        $price = isset($extendParam['giftPrice']) ? $extendParam['giftPrice'] : $textParam['giftPrice'];
        if(empty($price)){
            $price = 0;
        }
        if($price < $fullScreen['special_full_screen_diamond']){
            return false;
        }

        $ifSkip = true;// 飘屏是否有跳转 去踩房

        $configRes = [];
        if (($screenConfig = $fullScreen['screen_config']) && $extendParam){
            $screenConfig = json_decode($screenConfig, true);
            $configRes = $this -> initFullScreenConfig($screenConfig, $extendParam);
            if ($configRes && isset($configRes['skip'])){
                $ifSkip = $configRes['skip'];
            }
        }

        foreach ($textParam as $k => $v) {
            $keyStr = '$' . $k . '$';
            $v = htmlentities(trim($v));
            $fullScreen['text'] = str_replace($keyStr, $v, $fullScreen['text']);
        }
        if (!$ifSkip){//飘萍无需跳转
            $fullScreen['action'] = '';
            $fullScreen['action_img_url'] = '';
        }
        foreach ($actionParam as $k => $v) {
            $keyStr = '$' . $k . '$';
            $v = htmlentities(trim($v));
            $fullScreen['action'] = str_replace($keyStr, $v, $fullScreen['action']);
        }
        $showPage = [];
        if ($fullScreen['show_pages']){
            $showPage = explode(',', $fullScreen['show_pages']);
        }

        $data = [
            'k' => 80017,
            'bg_img' => $fullScreen['bg_img_url'],
            'icon_img' => $iconUrl ?? '',
            'action_img' => $fullScreen['action_img_url'],
            'action' => $fullScreen['action'],
            'text_float' => json_decode($fullScreen['text'], true),
            'screen_min_wealth' => 0,
            'show_pages' => (array)$showPage,
            'screen_msg_id' => $id,//飘屏id
            'show_room_ids' => empty($fullScreen['room_ids']) ? '' : $fullScreen['room_ids'],
        ];

        if ($id == 9 || $id == 22 || $id == 1 || $id == 18) {
            $data['hide_check'] = true;
        } else {
            $data['hide_check'] = false;
        }

	$res = $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:full_float_screen', $data);

        return $res;
    }


    /**
     * 初始化 飘萍配置
     * @param array $screenConfig
     * @return false
     */
    public function initFullScreenConfig($screenConfig=[], $extendParam=[])
    {
        if (empty($screenConfig) || empty($extendParam)){
            return false;
        }

        $fullScreenItemState = [];
        foreach ((array)$screenConfig as $key => $value) {
            switch ($key) {
                // 跳转
                case 'skip':
                    $res = $this -> initFullScreenSkip($value, $extendParam);
                    $fullScreenItemState['skip'] = $res;
                    break;

                default:
                    break;
            }
        }

        return $fullScreenItemState;
    }

    /**
     * 初始化飘萍 元素
     * @param array $extendParam 业务参数
     * @param array $screenConfig  飘萍配置
     * @return boolean  true：飘萍显示跳转  false:不限时跳转
     */
    public function initFullScreenSkip($screenConfig, $extendParam)
    {
        if (empty($screenConfig)){
            // 飘萍没有配置，默认显示跳转
            return true;
        }
        if (empty($extendParam)){
            return false;
        }


        $state = true;

        $log = [];
        foreach ((array)$screenConfig as $key => $config) {
            if (!$state){
                break;//所有规则全部允许跳转，则显示跳转
            }
            switch ($key) {
                case 'GiftRule':
                    $state = $this -> checkSkipGiftRule($extendParam, $config);
                    break;

                case 'RoomRule':
                    $state = $this -> checkSkipRoomIdRule($extendParam, $config);
                    break;

                default:
                    $state = 'false';
                    break;
            }
            $log['item'][$key] = $state;
        }
        $log['extendParam'] = $extendParam;
        $log['screenConfig'] = $screenConfig;
        // write_log(
        //     'sendFullScreen'.(isCli()?'-cli':''),
        //     '[INFO] 发送飘萍-跳转',
        //     $log
        // );
        return $state;
    }


    /**
     * 礼物金额是否满足跳转
     * @param $extendParam  礼物总金额
     * @param $config      飘萍是否跳转规则
     * @return bool
     */
    public function checkSkipGiftRule($extendParam, $config)
    {
        $giftPrice = $extendParam['giftPrice'] ?? 0;
        if (empty($giftPrice)){
            return false;
        }
        if (empty($config)){
            return false;
        }
        $priceMin = $config['priceMin'] ?? 0;
        if ($priceMin<=0){
            return false;
        }

        if ( $priceMin > $giftPrice ){
            return false;
        }

        return true;
    }

    /**
     * 指定房间显示跳转
     * @param $extendParam  最多金房间不限时 跳转
     * @param $config      飘萍是否跳转规则
     */
    public function checkSkipRoomIdRule($extendParam, $config)
    {
        if (empty($extendParam)){
            return false;
        }
        $roomId = $extendParam['roomId'] ?? 0;
        if ($roomId<=0){
            return false;
        }

        if (empty($config)){
            return false;
        }
        if ($config == 'NotMaximumGoldRoom'){
            // 排除最多斤房间
            $maximumGoldRoomIds = (new  MaximumGoldRoomServices()) -> getRoomIds();
            // write_log(
            //     'sendFullScreen'.(isCli()?'-cli':''),
            //     '[INFO] 发送飘萍-最多金房间',
            //     $maximumGoldRoomIds
            // );
            if ($maximumGoldRoomIds && is_array($maximumGoldRoomIds) && in_array($roomId, $maximumGoldRoomIds)){
                return false;
            }
        }

        return true;
    }


    /**
     * 发送系统消息-文案类型+跳转链接
     * 
     */
    public function sendSetUnionUserRateMsg($touserId,$msg,$action)
    {
        $data = [
            'k' => 110005, //信令code
            'msg' => $msg, //消息文案
            'action' => $action, //跳转链接 kkaudio://send_msg_action头部固定(?type=0对私弹窗)
            'action_text' => '立即查看>', //操作文案
            'timestemp' => time(), //创建时间
        ];
        $this->lib_rong->send_system_msg(11, $touserId, 'kk:send_msg_action', $data);
    }
    
    /**
     * 关注条/小屋广告内容变化通知客户端
     * @param $type
     * @param $params
     * @return bool
     */
    public function sendAdChangeMsg($type, $params)
    {
        $data = [
            'k' => 80018,
            'type' => $type,
            'is_change' => 1, //广告消息是否有变更,如果变更则有app主动更新广告内容
            'timestemp' => time(),
            'ad_content' => $params
        ];

        $data = json_encode($data, JSON_UNESCAPED_UNICODE);

        write_log(
            'MsgServices'.(isCli()?'-cli':''),
            'sendAdChangeMsg-[k:80018]',
            ['args'=>func_get_args()]
        );


        return $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:hammer_ad', $data);
    }

    /**达到某特权消息
     * @param $union_id
     * @param $user_id
     * @param $privilege_name
     */
    public function sendUnionPrivilege($union_id,$user_id,$privilege_name){
        $data = [
            'k' => 100006,
            'union_id' => $union_id,
            'title' => '公会【'.$privilege_name.'】已解锁',
            "content" => '您的公会解锁了新的公会特权，快来看看吧！',
            "user_id" => $user_id,
            'timestamp'=>time(),
        ];
        $this->lib_rong->send_system_msg(10, $user_id, 'kk:union_privilege', $data);
    }

    /**警告弹窗
     * @param $userId
     * @param $id
     * @return bool
     */
    public function systemAlert($userId ,$id)
    {
        $alertMsg = $this->modelSystem->get_system_alert($id);
        if (empty($alertMsg) || $alertMsg['switch'] <1) {
            return false;
        }
        if($alertMsg['type'] == 3){
            return true;
        }
        $data = [
            'k' => 80024,
            'image' => $alertMsg['image'],
            'title' => $alertMsg['title'],
            'content' => $alertMsg['content'],
            'action' => $alertMsg['action'],
            'type' => $alertMsg['type']
        ];
        $this->lib_rong->send_system_msg(11, $userId, "kk:alert", $data);
        return true;
    }

    /**邀请加入公会消息
     * @param $data
     */
    public function inviteJoinUnionMsg($data)
    {
        $params = [
            "k" => 100015,
            "unid" => $data['id'],
            "uname" => $data['name'],
            "image" => $data['image'],
            "auid" => $data['un_user_id'],//用户id
            "auname" =>$data['un_user_name'],//用户昵称
            "timestemp" => time(),
        ];
        $this->lib_rong->send_private_msg($data['un_user_id'], $data['invite_user_id'], 'kk:invite_join_union_msg', $params, 0);

    }

    /**道具发放道具
     * @param $userId
     * @param $msg
     * @return bool
     */
    public function sendPropMsg($userId ,$msg)
    {
        $data = [
            'k' => 80026,
            'title' => $msg,
        ];
        $this->lib_rong->send_system_msg(11, $userId, "kk:prop_update", $data);
        return true;
    }

    /**邀请加入家族消息
     * @param $room_id
     * @param int $user_id
     * @param $invite_user_id
     * @param int $status
     */
    public function roomAdminInvite($room_id ,$user_id = 0 ,$invite_user_id ,$status = 0)
    {
        if(empty($user_id)){
            $user = $this->user->get_current_user();
        }else{
            $user = $this->user->get_user($user_id);
        }
        if(empty($user)){
            return;
        }
        $room = $this->model_room->get_room($room_id);
        if(empty($room)){
            return;
        }
        $params = [
            "k" => 80027,
            "nickname" => $user['nickname'], //发送人昵称
            "user_id" => $user['user_id'],//发送人id
            "room_id" => $room_id, //房间id
            "room_name" =>$room['name'], //房间名称
            "room_image" =>$room['image'],//房间图
            "status" =>$status ,
            "timestamp" => time(),
        ];
        $this->lib_rong->send_private_msg($user_id, $invite_user_id, 'kk:invite_room_admin', $params, 0);

    }

    /**
     * 发送隐藏排行榜消息
     * @param $type
     * @param $params
     * @return bool
     */
    public function sendHideRanding($hide) {
        $data = [
            'k' => 80018,
            'hide' => $hide
        ];

        return $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:hide_ranking', $data);
    }

    /**
     * 发送图文私聊消息
     * @param int    $fromUserId 发送用户id
     * @param int    $toUserId   接收用户id
     * @param string $title      标题
     * @param string $desc       描述文本
     * @param string $image      图片地址
     * @param string $url        链接地址
     * @return void
     */
    public function sendShareActivityMsgTip($fromUserId, $toUserId, $title, $desc, $image, $url)
    {
        $data = [
            "k" => 90004,
            'url' => $url,
            'image' => $image,
            'desc' => $desc,
            'title' => $title,
        ];

        $this->lib_rong->send_private_msg($fromUserId, $toUserId, 'kk:share_activity', $data, 0);
    }

    /**
     * 发送私聊对话
     * @param $userId int 发送者ID
     * @param $toUserId int 接收者ID
     * @param $userNickname string 发送者昵称
     * @param $userPortrait string 发送者头像
     * @param $msg string 消息内容
     * @return bool
     */
    public function sendChatMsg($userId, $toUserId, $userNickname, $userPortrait, $msg)
    {
        $content = [
            "content" => $msg,
            "user" => [
                "id" => $userId,
                "name" => $userNickname,
                "portrait" => $userPortrait,
            ],
        ];
        return $this->lib_rong->send_private_msg($userId, $toUserId, "RC:TxtMsg", $content, 1);
    }

    /**
     * 发送萌新私信
     * @return array
     */
    public function novicePrivateMsg($userId, $toUserId, $msg)
    {
        $user = $this->user->get_user($userId, true);

        //只保留萌新3天内发送的私聊内容
        $time = 86400 * 3;
        if (time() - $user['create_timestamp'] > $time) {
            return [];
        }

        $chatType = "RC:TxtMsg";
        $this->noviceChatLog->addLog($userId, $toUserId, $chatType, $msg);

        return [];
    }

    /**
     * 私聊违规警告消息
     * @param $userId int 发送者ID
     * @param $toUserId int 接收者ID
     * @param $msg string 消息内容
     * @return bool
     */
    public function sendPrivateChatViolation($userId, $toUserId, $msg)
    {
        $content = [
            "msg" => $msg,
        ];
        return $this->lib_rong->send_private_msg($userId, $toUserId, "kk:chat_violation_private", $content, 0);
    }

    /**
     * 开启/关闭客户端灰度效果
     * 在一些悲伤的节日中，客户端需要全部显示灰色
     *
     * @param $hide int 0关闭;1开启
     * @return bool
     */
    public function sendHideGrayFilter($hide)
    {
        $data = [
            'k' => 80029,
            'gray_switch' => $hide,
        ];
        return $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:hide_gray_filter', $data);
    }

    /**
     * 用户图鉴点亮通知
     * @param $userId
     * @param $msg
     * @return bool
     */
    public function userHandbookLightMsg($userId ,$msg)
    {
        $data = [
            'k' => 170001,
            'title' => $msg,
        ];
        $this->lib_rong->send_system_msg(15, $userId, "kk:handbook_light", $data);
        return true;
    }

    /**
     * 用户进入图鉴通知
     * @param $userId
     * @param $msg
     * @return bool
     */
    public function userIntoHandbook($userId ,$msg)
    {
        $data = [
            'k' => 170002,
            'title' => $msg,
        ];
        $this->lib_rong->send_system_msg(15, $userId, "kk:handbook_into", $data);
        return true;
    }

    /**
     * 发送主播审核消息
     * @param $type
     * @param $params
     * @return bool
     */
    public function anchorVerifyMsg($userId, $cont) {
        $data = [
            "k" => 80101,
            "cont" => $cont
        ];
        $this->lib_rong->send_system_msg(11, $userId, 'kk:anchor_verify', $data);
    }

    /**
     * 面试官身份点击主播提醒消息
     */
    public function identityClickMsg($fromUserId, $toUserId, $cont) {
        $data = [
            'k' => 80102,
            'from_user_id' => $fromUserId,
            "to_user_id" => $toUserId,
            "content" => $cont,
            'timestemp' => time(),
        ];
        $this->lib_rong->send_system_msg($fromUserId, $toUserId, 'kk:identity_click', $data);
    }

    /**
     * 代理金豆转入通知
     */
    public function agentJdSendMsg($fromUserId, $toUserId, $msg, $logId, $num)
    {
        $data = [
            "k" => 70007,
            'msg' => $msg,
            "logId" => $logId,
            "num" => $num,
        ];
        $this->lib_rong->send_private_msg($fromUserId, $toUserId, 'kk:agent_jd_send', $data);
    }

    /**
     * 代理钻石转入通知
     */
    public function agentDiamondSendMsg($fromUserId, $toUserId, $msg, $logId, $num)
    {
        $data = [
            "k" => 70023,
            'msg' => $msg,
            "logId" => $logId,
            "num" => $num,
        ];
        $this->lib_rong->send_private_msg($fromUserId, $toUserId, 'kk:agent_diamond_send', $data);
    }

    /**
     * 代理钻石转入通知
     */
    public function agentKKSendMsg($fromUserId, $toUserId, $msg, $logId, $num)
    {
        $data = [
            "k" => 80013,
            'msg' => $msg,
            "logId" => $logId,
            "num" => $num,
        ];
        $this->lib_rong->send_private_msg($fromUserId, $toUserId, 'kk:agent_diamond_send', $data);
    }

    /**
     * 发送pk消息-文案类型
     * 
     */
    public function send_cross_pk_msg($toroomId, $roomInfo, $sendId, $type)
    {
        $data = [
            'k' => 70008, //信令code
            'data' =>[
                'msg' => '向你发起PK挑战', //消息文案
                'name' => $roomInfo['name'],//房间名称
                'img' => $roomInfo['image'],//房间图片
                'from_room_id' =>  $roomInfo['room_id'],//房间id
                'send_id' => $sendId,//邀请记录id
                'type' => $type,//1定向 2=随机
                'second' => 480,//8分钟等待时间
            ]
        ];
        return $this->lib_rong->send_room_msg($toroomId, $data);
    }

    /**
     * 通知本房间管理用户已经发起PK
     */
    public function our_cross_pk_msg($ourRoomId, $roomInfo, $sendId, $type){
        $data = [
            'k' => 70011, //信令code
            'data' =>[
                'msg' => '等待响应', //消息文案
                'name' => $roomInfo['name'],//房间名称
                'img' => $roomInfo['image'],//房间图片 
                'type' => $type,//1定向2随机
                'send_id' => $sendId,//邀请记录id
                'second' => 480,//8分钟等待时间
            ]
        ];
        return $this->lib_rong->send_room_msg($ourRoomId, $data);
    }
    
    /**
     * 取消通知 
     */
    public function our_cancel_cross_pk_msg($roomId, $sendId){
        $data = [
            'k' => 70015, //信令code
            'data' =>[
                'msg' => '取消PK', //消息文案
                'send_id' => $sendId,//邀请记录id
            ]
        ];
        return $this->lib_rong->send_room_msg($roomId, $data);
    }

    /**
     * 确认PK邀请通知
     */
    public function confirm_cross_pk_msg($toroomId, $roomInfo, $type, $pk_start, $pk_end, $sendId, $sendtype){
        $data = [
            'k' => 70009, //信令code
            'data' => [
                'msg' => '接收状态', //消息文案
                'name' => $roomInfo['name'],//房间名称
                'img' => $roomInfo['image'],//房间图片
                'send_id' => $sendId,//邀请id 
                'type' => $sendtype,//1定向 2=随机
                'confirm_status' => $type,//确认状态
                'pk_start' => $pk_start,//pk开始时间
                'pk_end' => $pk_end, //pk结束时间
            ] 
        ];

        return $this->lib_rong->send_room_msg($toroomId, $data);
    }

    /**
     * 自己房间管理发送接受邀请通知
     */
    public function our_confirm_cross_pk_msg($ouroomId, $roomInfo, $type, $pk_start, $pk_end, $sendId, $sendtype){
        $data = [
            'k' => 70012, //信令code
            'data' => [
                'msg' => '接收状态', //消息文案
                'name' => $roomInfo['name'],//房间名称
                'img' => $roomInfo['image'],//房间图片 
                'send_id' => $sendId,//邀请id 
                'confirm_status' => $type,//确认状态
                'type' => $sendtype,//1定向 2=随机
                'pk_start' => $pk_start,//pk开始时间
                'pk_end' => $pk_end, //pk结束时间
            ]
        ];

        return $this->lib_rong->send_room_msg($ouroomId, $data);
    }

    /**
     * 首功特效消息
     */
    public function first_gift_cross_pk_msg($allRoomIds, $from_user_id, $giftInfo){
        foreach($allRoomIds as $room_id){
            $data = [
                'k' => 70010, //信令code
                'data'=> [
                    'msg' => '首功特效', //消息文案
                    'roomIds' => $allRoomIds,//接收房间
                    'send_user_id' => $from_user_id,//送礼人
                    'giftInfo' => $giftInfo,//送出礼物详情
                ]  
            ];
            $msg[] = $this->lib_rong->send_room_msg($room_id, $data);
        }
        return $msg;
    }

    /**
     * 结束PK通知
     */
    public function end_cross_pk_msg($roomId, $joionUserData, $winnerRoom, $count, $point, $fromImg, $toRoomImg,$pk_status){
        $data = [
            'k' => 70013, //信令code
            'data' => [
                'msg' => '结束pk', //消息文案
                'winnerRoomId' => $winnerRoom,//胜利房间id
                'winnerCount' => $count,//胜利者胜利次数
                'point' => $point,//双方点数
                'pk_status' => $pk_status,//PK结算状态
                'from_room_img' => $fromImg,//发起方图片 
                'to_room_img' => $toRoomImg,//对手图片
                'joionUserData' => $joionUserData,//参与过的用户
            ]
            
        ];
        $msg = $this->lib_rong->send_room_msg($roomId, $data);
        return $msg;
    }

    //PK房间中排行榜实时排名变化
    public function send_now_cross_pk_msg($roomid, $data){
        $data = [
            'k' => 70014, //信令code
            'data' => [
                'msg' => '对战详情', //消息文案
                'selfRoomPoint' => $data['selfRoomPoint'],
                'otherRoomPoint' => $data['otherRoomPoint'],
                'selfRank' => $data['selfRank'],
                'otherRank' => $data['otherRank'], 
                'now_time' => time(),
                'selfPointList' => $data['selfPointList'],
            ] 
        ];
        $msg = $this->lib_rong->send_room_msg($roomid, $data);
        return $msg; 
    }

    //PK房间中排行榜实时排名变化
    public function pk_status_msg($roomid, $data){
        $data = [
            'k' => 70016, //信令code
            'msg' => $data, //消息文案
        ];
        $msg = $this->lib_rong->send_room_msg($roomid, $data);
        return $msg; 
    }

    /*
     * 留言板通知
     */
    public function lybMsg($fromUserId, $toUserId, $msg, $createTime, $endTime, $jumpUrl)
    {
        $userInfo = (new User())->get_user($fromUserId);

        $imgUrl = build_url('/app/lyb.svga');

        $data = [
            "k" => 70020,
            "user_id" => $fromUserId,
            "user_nickname" => $userInfo['nickname'],
            "user_image" => $userInfo['images'][0],
            'msg' => $msg,
            'created_at' => $createTime,
            'end_at' => $endTime,
            "img_url" => $imgUrl,
            "jump_url" => $jumpUrl,
        ];
        $this->lib_rong->send_system_msg(16, $toUserId, 'kk:lyb_msg', $data);
    }

    //房间内游戏公屏游戏消息
    public function roomGameMsg($roomid, $data){
        $data = [
            'k' => 70021, //信令code
            'wishdata' => $data, //消息文案
        ];

        $msg = $this->lib_rong->send_room_msg($roomid, $data);
        return $msg;
    }

    //房间内游戏公屏游戏消息
    public function roomGameMsg2($roomid,$data){
        $data = [
            'k' => 70027, //信令code
            'wishdata' => $data, //消息文案
        ];
//        $msg = $this->lib_rong->send_room_msg($roomid, $data);
        $msg = $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:audio_room', $data);
//        write_log('sendFullScreen', '发送世界消息:response', $msg);
        return $msg;
    }

    //星辰变抽奖公屏消息
    public function roomWishPoolMsg($roomid, $data){
        $data = [
            'k' => 70022, //信令code
            'wishdata' => $data, //消息文案
        ];

        $msg = $this->lib_rong->send_room_msg($roomid, $data);
        return $msg; 
    }
    //星辰变抽奖公屏消息
    public function roomWishPoolMsg2($roomid, $data){

        $data = [
            'k' => 70026, //信令code
            'wishdata' => $data, //消息文案
        ];
//        $msg = $this->lib_rong->send_room_msg($roomid, $data);
        $msg= $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:audio_room', $data);
//         write_log('sendFullScreen', '发送世界消息:70026', $msg);
        return $msg;
    }

    //万神殿抽奖世界公屏消息
    public function defenderWorldMsg($data){

        $data = [
            'k' => 70028, //信令code
            'wishdata' => $data, //消息文案
        ];
        $msg= $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:audio_room', $data);
        return $msg;
    }

    //万神殿抽奖房间公屏消息
    public function defenderRoomMsg($roomid, $data){
        $data = [
            'k' => 70029, //信令code
            'wishdata' => $data, //消息文案
        ];

        $msg = $this->lib_rong->send_room_msg($roomid, $data);
        return $msg;
    }

    //万神殿倒计时消息
    public function defenderCountdownMsg($data){

        $data = [
            'k' => 70030, //信令code
            'wishdata' => $data, //消息文案
        ];
        $msg= $this->lib_rong->publish_chat_room(11, $this->defender_room_id, 'kk:audio_room', $data);
        return $msg;
    }

    //万神殿更换阶段消息
    public function defenderChangePoolMsg($data){

        $data = [
            'k' => 70031, //信令code
            'wishdata' => $data, //消息文案
        ];
        $msg= $this->lib_rong->publish_chat_room(11, $this->defender_room_id, 'kk:audio_room', $data);
        return $msg;
    }

    //万神殿更换擂主消息
    public function defenderChangeWinnerMsg($data){

        $data = [
            'k' => 70032, //信令code
            'wishdata' => $data, //消息文案
        ];
        $msg= $this->lib_rong->publish_chat_room(11, $this->defender_room_id, 'kk:audio_room', $data);
        return $msg;
    }

    /**
     * 万神殿-滚动公告
     */
    public function sendDefender($msgData){
        //全服公告
        $data = [
            "k" => 30072,
            "universe_data" => [
                "scoll_msg" => $msgData,
            ],
        ];
        $this->lib_rong->publish_chat_room(11, $this->defender_room_id, 'kk:full_universe_scoll_msg', $data);
    }

    //幸运礼物世界公屏消息
    public function luckGiftWorldMsg($fromUserId, $giftName, $giftNum, $diamondNum, $nickname, $multiple = '', $is_sound = '1', $winRes = []){

        $data = [
            'k' => 70033, //信令code
            "fid" => intval($fromUserId),
            "fnn" => $nickname,
            'gift_name' => $giftName,
            'gc' => $giftNum,
            'diamond_num' => $diamondNum,
            'multiple' => $multiple,
            'is_sound' => $is_sound,
            'to_nickname' => '',
            'win_list' => $winRes,
        ];
        $msg= $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:audio_room', $data);
        return $msg;
    }

    //星辰变抽奖公屏消息
    public function worldHopeDrawMsg($data){
        $data = [
            'k' => 70034, //信令code
            'wishdata' => $data, //消息文案
        ];

        $msg = $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:audio_room', $data);
        return $msg;
    }

    //星辰变开启高级奖池消息
    public function roomOpenPoolMsg($roomid, $data){
        $data = [
            'k' => 70024, //信令code
            'msgData' => $data, //消息文案
        ];
        
        $msg = $this->lib_rong->send_room_msg($roomid, $data);
        return $msg; 
    }

    /**
     * 赠送礼物
     */
    public function sendGiftText($send_user_id, $recv_user_id, $giftId, $giftNum, $giftName, $str1)
    {
        $data = [
            "k" => 70017,
            "gid" => $giftId,
            "gc" => $giftNum,
            "gn" => $giftName,
            "str1" => $str1,
        ];
        $this->lib_rong->send_private_msg($send_user_id, $recv_user_id, 'kk:sendGiftText', $data);
    }

    /**
     * 背包礼物批量赠送消息
     */
    public function giftbagbatchMsg($fromUserId, $toUserId, $str1, $giftList)
    {
        $data = [
            "k" => 70018,
            "str1" => $str1,
            "gift_list" => $giftList,
        ];

        $this->lib_rong->send_private_msg($fromUserId, $toUserId, 'kk:sendGiftBatchText', $data);
    }

    /*
     * 留言板通知
     */
    public function lybMsgSend($fromUserId, $toUserId, $msg, $createTime, $endTime, $jumpUrl, $imgUrl='/app/lyb.svga')
    {
        $userInfo = (new User())->get_user($fromUserId);

        $imgUrl = build_url($imgUrl);

        $data = [
            "k" => 70020,
            "user_id" => $fromUserId,
            "user_nickname" => $userInfo['nickname'],
            "user_image" => $userInfo['images'][0],
            'msg' => $msg,
            'created_at' => $createTime,
            'end_at' => $endTime,
            "img_url" => $imgUrl,
            "jump_url" => $jumpUrl,
        ];
        $this->lib_rong->send_system_msg(16, $toUserId, 'kk:lyb_msg', $data);
    }

    /**
     *  用户充值钻石数满足系统配置全屏飘屏限制钻石数,发送融云通知,告诉用户可以看到全屏飘屏通知权限 
     */
    public function can_see_full_screen_msg($user_id,$data){
        $data = [
            'k' => 80016,
            'show_screen_premission' => $data,
        ];
        $res = $this->lib_rong->send_system_msg(13, $user_id, 'kk:can_see_full_screen', $data);
        return $res;
    }

    //通知用户更新房间banner
    public function roomBannerMsg($roomid, $userId){
        $data = [
            'k' => 70025, //信令code
            'type' => 3, //消息文案
            "fid" => $userId,
        ];

        $msg = $this->lib_rong->send_room_msg($roomid, $data);
        return $msg; 
    }

    /**
     * 用户锁麦消息
     */
    public function userMicroLockMsg($userId, $log, $status)
    {
        $roomInfo = $this->model_room->get_room($log['room_id']);
        $data = [
            "k" => 30070,
            "micro_lock" => [
                "room_id" => $log['room_id'],
                "micro_id" => $log['micro_id'],
                "lock_user_id" => $log['lock_user_id'],
                "room_user_id" => $log['room_user_id'],
                "status" => $status,//1=锁麦 0=解锁
                "room_name" => empty($roomInfo['name']) ? '' : $roomInfo['name'],
            ],
        ];
        $res = $this->lib_rong->send_system_msg(13, $userId, 'kk:user_room_micro_lock', $data);
    }

    /**
     * 星辰变-滚动公告
     */
    public function sendUniverse($msgData, $allStart, $luckId, $leaveMinutes){
        return true;
        //全服公告
        $data = [
            "k" => 30071,
            "universe_data" => [
                'progress' => $allStart,//全服值
                'luck_id' => $luckId,//目前奖池id
                'leaveMinutes' => $leaveMinutes,//剩余分钟数
                "scoll_msg" => $msgData,
            ],
        ];
        $this->lib_rong->publish_chat_room(11, $this->chat_room_id, 'kk:full_universe_scoll_msg', $data);
        write_log('pop_log','INFO星辰变滚动消息',$data);
    }

    /**
     * 发送系统消息-文案类型+跳转链接
     * 
     */
    public function sendUserWithUrlMsg($touserId, $msg, $action, $actionText)
    {
        $data = [
            'k' => 110005, //信令code
            'msg' => $msg, //消息文案
            'action' => $action, //跳转链接 kkaudio://send_msg_action头部固定(?type=0对私弹窗)
            'action_text' => $actionText, //操作文案
            'timestemp' => time(), //创建时间
        ];
        $this->lib_rong->send_system_msg(11, $touserId, 'kk:send_msg_action', $data);
    }

}
